<template>
    <div class="box">
        <div class="left">
            <h2>FRUITSHOP 后台管理</h2>
        </div>
        <div class="right">
            <span>欢迎您：{{admin}}</span>
            <span @click="logout">注销</span>
        </div>
    </div>
</template>

<script>
import Axios from 'axios';
export default {
    data(){
        return{
            admin:''
        }
    },
    created (){
       this.getuser()
    },
    methods:{
        //保持登录状态
      getuser(){
       Axios.get('/users/islogin').then(res=>{

           if(res.data.islogin){
               this.admin=res.data.name;//修改页面显示名字
           }else{
               this.$router.push('/Login');
           }

       })
      },
      //退出登录状态
      logout(){
      Axios.get('/users/logout').then(res=>{
        if(res.data){
             this.$router.push('/Login') //退出登录状态，跳转登录页面
        }

      })
      }
    }
};
</script>

<style scope>
.box {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
h2 {
    font-size: 17px;
    margin-left: 0px;
}
.right {
    display: flex;
    justify-content: center;
}

.right span {
    font-size: 14px;
    color: white;
    padding: 0px 20px;
    cursor: pointer;
}

.right :nth-child(2):hover {
    background: rgb(192, 67, 67);
}
</style>
